package org.yxj.picturerecognition;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;

import org.yxj.picturerecognitionlibrary.PictureRecognitionView;

public class MainActivity extends AppCompatActivity {

    private ImageView imResult;
    private PictureRecognitionView mPictureRecognitionView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imResult = findViewById(R.id.imResult);
        mPictureRecognitionView = findViewById(R.id.mPictureRecognitionView);
        Glide.with(this)
                .asBitmap()
                .load("https://i.zhaojinapp.com/undefined/2312/11/2312111627551579.jpg")
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        mPictureRecognitionView
                                // 回调
                                .setCheckRectListener(new PictureRecognitionView.CheckRectListener() {
                                    @Override
                                    public void onResult(Bitmap bitmap) {
                                        imResult.setImageBitmap(bitmap);
                                    }
                                })
                                .setLineColor(Color.YELLOW)
                                // 设置选取的位置
                                .setCoordinateBean(100, 200, 500, 500)
                                //设置原图
                                .init(resource);
                    }
                });


        imResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPictureRecognitionView.upDataCoordinateBean(200, 100, 600, 400);
            }
        });
    }
}